package com.zl.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class ZLUtil {

	private static String jdbc_url = "jdbc:mysql://119.29.196.89:3306/db_book";//地址
	private static String jdbc_userName = "zhangli";//用户名
	private static String jdbc_password = "123456";//密码
	private static String jdbc_name = "com.mysql.jdbc.Driver";//驱动

	
	//一个连接 一个关闭
	/**
	 * 获取数据库连接
	 * @return
	 * @throws Exception
	 */
	public static Connection getConnect() throws Exception {
		
		Class.forName(jdbc_name);
		Connection connection = DriverManager.getConnection(jdbc_url, jdbc_userName, jdbc_password);
		return connection;
	}
	
	/**
	 * 关闭连接
	 * @param con
	 * @throws Exception
	 */
	public static void colseConnect(Connection con) throws Exception {
		
		if (con != null) {
			con.close();
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		ZLUtil zlUtil = new ZLUtil();
		try {
			zlUtil.getConnect();
			System.out.println("数据库连接成功！");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			System.out.println("数据库连接失败！");
		}
	}

}
